<template>
	<view>
		<div>
			<navitop> 
				<i class="iconfont icon-jiantou-copy" slot="left-slot" @click="outlot"></i>
				<span slot="center-slot">详情</span>
				<i class="iconfont icon-youcecaidan" slot="right-slot"  @click="tapPopup(data)"></i>
			</navitop>
		</div>
		
		<div class="detial" :style='window_height'>
			<div style="background-color: #f0f0f0;" class="public_mag_top"></div>
			<scroll-view class="staff_b" scroll-y="true" touch-action=none; >
				<div class="detial_text">
					<div>
						<text>活动名称:</text><text>{{dataSorce.activityTitle}}</text>
					</div>
					<div>
						<text>活动类型:</text><text>{{dataSorce.activityType}}</text>
					</div>
					<div>
						<text>活动状态:</text><text>{{dataSorce.activityState}}</text>
					</div>
					<div>
						<text>负责人:</text><text>{{dataSorce.activityOwnerName}}</text>
					</div>
					<div>
						<text>预期收益(元):</text><text>{{dataSorce.anticipatedRevenue}}</text>
					</div>
					<div>
						<text>实际成本(元):</text><text>{{dataSorce.actualCost}}</text>
					</div>
					<div>
						<text>预算成本(元):</text><text>{{dataSorce.budgetCost}}</text>
					</div>
					<div>
						<text>期望成功率(%):</text><text>{{dataSorce.expectedSuccessRate}}</text>
					</div>
					<div @click="altime(1)">
						<text>开始时间:</text><text>{{dataSorce.startTime}}</text>
					</div>
					<div @click="altime(2)">
						<text>结束时间:</text><text>{{dataSorce.endTime}}</text>
					</div>
				</div>
			</scroll-view>
		</div>
		<!-- 弹窗组件 -->
		<popus ref="alert">
			<alertcenter @row="row" :titles="titles" :rundata="rundata" :dataSorc="datas" ></alertcenter>
		</popus>
		
		<popus ref="activi_alert">
			<div :style="alertWidth">
				<active @closes="closes" :selid="selid"></active>
			</div>
		</popus>
		
		
		<chunLeiPopups v-model="value" :popData="data" @tapPopup="tapPopup" :x="345" :y="95" placement="top-end"></chunLeiPopups>
		
	</view>
</template>

<script>
	import navitop from '@/components/common/navi-top'
	import chunLeiPopups from "@/components/chunLei-popups/chunLei-popups"
	import alertcenter from '@/pages/common/common/alert/alertgx'
	import kxTime from "@/components/kx-datetime/kx-datetime"	
	import popus from '@/uni_modules/uni-popup/components/uni-popup/uni-popup'
	import active from '@/pages/common/index/subpage/activety/activitydetedit'
	import {acdetail,activitysave,namelist,dataList,batchDelete} from '@/common/api/job/jobapi.js'
	import {user_name_list} from "@/common/api/job/alert.js"
	export default {
		components:{
			navitop,
			alertcenter,
			chunLeiPopups,
			popus,
			kxTime,
			active
		},
		props:{
			selid: {
				default: ''
			}
		},
		data(){
			return {
				window_height:'',
				dataSorce: [],
				rundata: [],
				datas: [],
				data: [
					{title:"编辑",code:1,icon: 'icon-bianji'},
					{title:"删除",code:3,icon: 'icon-shanchu'},
					{title:"商机",code:2,icon: 'icon-bianji'},
				],
				date: '', //需要展示的时间数据
				enddate: "2500", // 时间段的终止时间，不设置默认当前之间终止
				startdate: "2020" ,//时间段的开始时间，不设置默认计算机最初时间
				value:false,
				titles: '商机列表',
				heigs:'',
				heigsdiv: 0,
				status: [{name:'计划中',code:'activityState'},{name:'执行中',code:'activityState'},{name: '终止',code:'activityState'},{name: '完成',code:'activityState'}],
				time_code: '',	// 获取选中时间code
				actv_class: [],	// 特色	
				user_name: [],	// 负责人
				alertWidth:''
				
			}
		},
		mounted() {
			let _this = this;
			uni.getSystemInfo({
			    success: function (res) {
					_this.alertWidth = 'width:' + res.windowWidth + 'px;'
			    }
			});
			uni.onKeyboardHeightChange(res => {
				res.height = res.height + 50;
				this.heigsdiv = 'height:' + res.height  + 'px;' ;
				this.heigs = 'height:' + res.height + 'px;' ;
			})
		   const res = uni.getSystemInfoSync();
		   this.window_height = 'height:' + res.windowHeight + 'px;';
		   this.acdetails();
			  
			  // 获取下拉列表
			namelist({source: 'activity'}).then((rows) =>{
				if(rows.code == 200){
					this.actv_class = rows.data[0].val.split(',')
				}
			})
			
			// 获取员工列表
			dataList({isLoadUser: 2}).then((rows) => {
				if(rows.code == 200){
					console.log(rows.data)
					for(let i in rows.data){
						if(rows.data[i].id.split('_')[1] == "user"){
							this.user_name.push(rows.data[i]);
						}
					}
				}
			})
		},
		methods:{
			
			// 关闭窗口
			outlot(){
				this.$emit('closes',2)
			},
			
			closes(){
				this.$refs.activi_alert.close();
			},
			
			// 状态
			statu(){
				this.titles = '活动状态'
				this.datas = this.status;
				this.$refs.alert.open('bottom');
			},
			
			// 类型
			class_actv(){
				let rusn = [];
				for(let i in this.actv_class){
					rusn.push({name:this.actv_class[i],code:'activityType'})
				}
				this.titles = '活动类型'
				this.datas = rusn;
				this.$refs.alert.open('bottom');
			},
			
			// 负责人
			name_click(){
				this.titles = '负责人'
				this.user_name.forEach(item => {
					this.$set(item,'code','activityOwnerName')
				})
				this.datas = this.user_name;
				this.$refs.alert.open('bottom');
			},
			
			// 获取时间code
			altime(val){
				this.time_code = val;
			},
			
			// 获取时间
			kxdatetime(e){
				if(this.time_code == 1){
					this.dataSorce.startTime = e.substr(0,10);
				}
				if(this.time_code == 2){
					this.dataSorce.endTime = e.substr(0,10);
				}
			},
			
			//  获取列表
			acdetails(){
				acdetail({id:this.selid}).then((rows) => {
					if(rows.code == 200){
						this.dataSorce = rows.data;
					}
					// console.log(this.dataSorce)
				})
			},
			
			//  获取弹窗返回结果
			row(val){
				this.dataSorce[val.code] = val.name;
				this.$refs.alert.close();
			},
			
			// 获取商机列表
			tapPopup(val){
				this.value = true;
				if(val.code == 2){
					this.$refs.alert.open('bottom');
					this.dataSorce.businessList.forEach(item => {
						this.$set(item,'name',item.title)
					})
					this.datas = this.dataSorce.businessList;
				}
				if(val.code == 1){
					this.$refs.activi_alert.open('left')
				}
				
				if(val.code == 3) {
					batchDelete([this.dataSorce.id]).then((reslut)=>{
						if(reslut.code == 200){
							uni.showToast({
								title: '已删除'
							})
							setTimeout(() => {
								this.$refs.alert.close();
							},1500)
						}else{
							uni.showToast({
								title: reslut.message,
								icon: 'error'
							})
						}
					})
				}
			},
			// 保存
			 okclick(){
				 activitysave(this.dataSorce).then((rows)=> {
					 if(rows.code == 200){
						 uni.showToast({
						 	title: '保存成功'
						 })
						 setTimeout(() => {
							 this.$emit('closes',1)
						 })
					 }else{
						 uni.showToast({
						 	title: reslut.message,
							icon: 'error'
						 })
					 }
				 })
			 }
			
			
		}
	}
	
</script>

<style scoped lang="scss">
.detial {
	height: 100%;
	padding-top: 95rpx;
	width: 100%;
	background-color: #fff;
	.detial_text{
		div {
			width: 95%;
			display: flex;
			// justify-content: space-between;
			margin: auto;
			height: 90rpx;
			line-height: 89rpx;
			border-bottom: 1px solid #f0f0f0;
		}
		
	}
	.detial_text text{
		// width: 40%;
		text-align: left;
		padding-left: 30rpx;
		padding-right: 20rpx;
		color: #808080;
	}
	.detial_text span{
		// padding-left: 30rpx;
	}
	.detial_text input{
		// height: 90rpx;
		width: 50%;
		border: 1px solid #cacaca;
		border-radius: 4px;
	}
	
	input:hover {
			border: 1px solid #1890ff;
	}	
}
.stats {
	width: 200px;
	height: 100rpx;
	z-index: 1;
}
.title {
	margin-top: 1px;
	height: 90rpx;
	background-color: #fff;
	line-height: 90rpx;
	padding-left: 10px;
	border-bottom: 1px solid #f0f0f0;
	border-radius: 4px;
}
.second_list {
	height: 90rpx;
	margin-top: 1px;
	background-color: #fff;
	line-height: 90rpx;
	padding-left: 20px;
	border-radius: 4px;

}
</style>
